package wafa.criterion;

import com.ibm.mm.sdk.common.DKConstant;
import com.ibm.mm.sdk.common.DKConstantICM;
import com.ibm.mm.sdk.common.DKDDO;
import com.ibm.mm.sdk.common.DKException;
import com.ibm.mm.sdk.common.DKNVPair;
import com.ibm.mm.sdk.common.DKPidICM;
import com.ibm.mm.sdk.common.dkResultSetCursor;
import com.ibm.mm.sdk.server.DKDatastoreICM;

import wafa.modelDocument.Index;


public class TestCriterion  {
	static String database = "serverged31";
	static String userName = "icmadmin";
	static String password = "icmadmin";
	static String schema = "SCHEMA=" + "ICMADMIN";

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// 192.168.0.30
		try {

			DKDatastoreICM dsICM = new DKDatastoreICM();
			System.out.println("chui la!!!!!!!rrr!!");
//			dsICM.connect(database, userName, password, schema);
			System.out.println("chui la!!!!!!!!!");

			System.out.println("les information d la connex"
					+ dsICM.schemaName());
			System.out.println("les information d la connex"
					+ dsICM.datastoreType());
			System.out.println("les information d la connex"
					+ dsICM.schemaName());
			// String query="//WASSIL";

			Index<String> index1 = new Index<String>();
			index1.setKey("cat");
			index1.setValue("1000");
			Index<String> index2 = new Index<String>();
			index2.setKey("exe");
			index2.setValue("1000");
			CriteriaECMIBM criteria = new CriteriaECMIBM();
			criteria.setFamily("CNSS");
			Criterion criterion = Restriction.superieur(index1.getKey(),index1.getValue());
			System.out.println("1"+criteria.stringQuery);
			criteria.add(Restriction.or(criterion, Restriction.superieurEgale(index2.getKey(),index2.getValue())));
			criteria.add(criterion);
			criteria.add(Restriction.or(criterion, criterion));
			System.out.println("2"+criteria.stringQuery);
			criteria.endQuery();
			System.out.println("---"+criteria.stringQuery);
//			String query = criteria.stringQuery;
//			DKNVPair options[] = new DKNVPair[3];
//			options[0] = new DKNVPair(DKConstant.DK_CM_PARM_MAX_RESULTS, "0"); 
//			options[1] = new DKNVPair(DKConstant.DK_CM_PARM_RETRIEVE,
//					new Integer(DKConstant.DK_CM_CONTENT_ATTRONLY));
//			// Specify any Retrieval Options desired. Default is ATTRONLY.
//			options[2] = new DKNVPair(DKConstant.DK_CM_PARM_END, null);
//
//			dkResultSetCursor cursor = dsICM.execute(query,
//					DKConstantICM.DK_CM_XQPE_QL_TYPE, options);
//			System.out.println("Executed:  Obtain all Insurance Claims & Adjustments in System.");
//			System.out.println("Accessing Res"
//					+ ""
//					+ ""
//					+ "."
//					+ ""
//					+ ""
//					+ "ult Set Cursor...");
//
//			DKDDO ddo;
//			String itemId = "";
//
//			while ((ddo = cursor.fetchNext()) != null) { // Get the next ddo &
//															// stop when ddo ==
//															// null.
//
//				itemId = ((DKPidICM) ddo.getPidObject()).getItemId();
//				System.out.println("     - Item ID:  " + itemId + "("
//						+ ddo.getPidObject().getObjectType() + ")"); // Print
//																		// Item
//																		// ID &
//																		// Object
//																		// Type
//			}
//			System.out.println("nbr " + cursor.getPosition());
//			// IMPORTANT STEP:
//			cursor.destroy(); // Close & Destroy Cursor, Ending Implied
//								// Transaction.
//
//			System.out.println("Accessed Result Set Cursor.");
//
//			dsICM.disconnect();
//			dsICM.destroy();
//			System.out.println("fin");
		} catch (DKException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println(e.getMessage());
			e.getMessage();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
